package com.community.backend.service.impl;

import com.community.backend.mapper.NoticeMapper;
import com.community.backend.pojo.Notice;
import com.community.backend.pojo.dto.NoticeQueryDTO;
import com.community.backend.service.NoticeService;
import com.community.backend.utils.PageResult;
import com.community.backend.utils.Result;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class NoticeServiceImpl implements NoticeService {
    @Autowired
    private NoticeMapper noticeMapper;

    @Override
    public PageResult pageQuery(NoticeQueryDTO noticeQueryDTO) {
        PageHelper.startPage(noticeQueryDTO.getCurrentPage(),noticeQueryDTO.getPageSize());
        Page<Notice> page = noticeMapper.pageQuery(noticeQueryDTO);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void save(Notice notice) {
        notice.setStatus("草稿");
        noticeMapper.insert(notice);
    }

    @Override
    public void update(Notice notice) {
     noticeMapper.update(notice);
    }

    @Override
    public void deleteById(Integer noticeId) {
        noticeMapper.deleteById(noticeId);
    }

    @Override
    public void updateSort(Integer noticeId, Integer sort) {
        noticeMapper.updateSort(noticeId,sort);
    }

    @Override
    public Notice NoticeDetail(Integer noticeId) {
        Notice notice = noticeMapper.NoticeDetail(noticeId);
        return notice;
    }

    @Override
    public List<Notice> list() {
        return noticeMapper.list();
    }


}
